using System;
using Csla;
using System.Collections;
namespace Manor.Business.Article
{
	[Serializable]
	public partial class ArticleDescription : BusinessBase<ArticleDescription>
	{

		#region Business Methods
		public static readonly PropertyInfo<int> ArtMpardIdProperty = RegisterProperty<int>(c => c.ArtMpardId);
		public int ArtMpardId
		{
			get {return GetProperty(ArtMpardIdProperty); }
			set {SetProperty(ArtMpardIdProperty, value); }
		}

		public static readonly PropertyInfo<int> MparArtMparIdProperty = RegisterProperty<int>(c => c.MparArtMparId);
		public int MparArtMparId
		{
			get {return GetProperty(MparArtMparIdProperty); }
			set {SetProperty(MparArtMparIdProperty, value); }
		}

		public static readonly PropertyInfo<string> LangProperty = RegisterProperty<string>(c => c.Lang);
		public string Lang
		{
			get {return GetProperty(LangProperty); }
			set {SetProperty(LangProperty, value); }
		}

		public static readonly PropertyInfo<string> DescrProperty = RegisterProperty<string>(c => c.Descr);
		public string Descr
		{
			get {return GetProperty(DescrProperty); }
			set {SetProperty(DescrProperty, value); }
		}

		public static readonly PropertyInfo<string> ShortDescrProperty = RegisterProperty<string>(c => c.ShortDescr);
		public string ShortDescr
		{
			get {return GetProperty(ShortDescrProperty); }
			set {SetProperty(ShortDescrProperty, value); }
		}

		public static readonly PropertyInfo<DateTime> InsDatProperty = RegisterProperty<DateTime>(c => c.InsDat);
		public DateTime InsDat
		{
			get {return GetProperty(InsDatProperty); }
			set {SetProperty(InsDatProperty, value); }
		}

		public static readonly PropertyInfo<string> InsOperProperty = RegisterProperty<string>(c => c.InsOper);
		public string InsOper
		{
			get {return GetProperty(InsOperProperty); }
			set {SetProperty(InsOperProperty, value); }
		}

		public static readonly PropertyInfo<DateTime> MutDatProperty = RegisterProperty<DateTime>(c => c.MutDat);
		public DateTime MutDat
		{
			get {return GetProperty(MutDatProperty); }
			set {SetProperty(MutDatProperty, value); }
		}

		public static readonly PropertyInfo<string> MutOperProperty = RegisterProperty<string>(c => c.MutOper);
		public string MutOper
		{
			get {return GetProperty(MutOperProperty); }
			set {SetProperty(MutOperProperty, value); }
		}

		protected override object GetIdValue()
		{
			return ArtMpardId;
		}

		#endregion

		#region Business Rules
		protected override void AddBusinessRules()
		{
			base.AddBusinessRules();

			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(ArtMpardIdProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(MparArtMparIdProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(LangProperty, 1));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(LangProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(DescrProperty, 40));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(DescrProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(ShortDescrProperty, 20));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(ShortDescrProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(InsDatProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(InsOperProperty, 15));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(InsOperProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(MutOperProperty, 15));
		}

		#endregion

		#region Factory Methods
		internal static ArticleDescription New()
		{
			var articledescription = DataPortal.CreateChild<ArticleDescription>();
			return articledescription;
		}

		internal static ArticleDescription Get(object fetchData)
		{
			return DataPortal.FetchChild<ArticleDescription>(fetchData);
		}

		private ArticleDescription()
		{
			/* Require use of factory methods */ 
		}

		#endregion

		#region Data Portal
		[RunLocal]
		protected override void Child_Create()
		{
			//load default values here
			//omit this override if you have no defaults to set
			base.DataPortal_Create();
		}

		// ReSharper disable UnusedMember.Local
		private void Child_Fetch(object fetchData)
		// ReSharper restore UnusedMember.Local
		{
			using (BypassPropertyChecks)
			{
				//Stub: Write fetchdata to the CSLA Object 
				//LoadProperty(ArtMpardIdProperty, ???ArtMpardId);
				//LoadProperty(MparArtMparIdProperty, ???MparArtMparId);
				//LoadProperty(LangProperty, ???Lang);
				//LoadProperty(DescrProperty, ???Descr);
				//LoadProperty(ShortDescrProperty, ???ShortDescr);
				//LoadProperty(InsDatProperty, ???InsDat);
				//LoadProperty(InsOperProperty, ???InsOper);
				//LoadProperty(MutDatProperty, ???MutDat);
				//LoadProperty(MutOperProperty, ???MutOper);
			}

		}

		 [Transactional(TransactionalTypes.TransactionScope)]
		// ReSharper disable UnusedMember.Local
		// ReSharper disable UnusedParameter.Local
		private void Child_Insert(object parent)
		// ReSharper restore UnusedParameter.Local
		// ReSharper restore UnusedMember.Local
		{
			using (BypassPropertyChecks)
			{
				//Stub: Write Data to a new DB Object
				//dbObject.ArtMpardId = ArtMpardId;
				//dbObject.MparArtMparId = MparArtMparId;
				//dbObject.Lang = Lang;
				//dbObject.Descr = Descr;
				//dbObject.ShortDescr = ShortDescr;
				//dbObject.InsDat = InsDat;
				//dbObject.InsOper = InsOper;
				//dbObject.MutDat = MutDat;
				//dbObject.MutOper = MutOper;
				//dbObject.Save();
			}

			FieldManager.UpdateChildren(this);
		}

		// ReSharper disable UnusedMember.Local
		 [Transactional(TransactionalTypes.TransactionScope)]
		private void Child_Update(object parent)
		// ReSharper restore UnusedMember.Local
		{
			if (IsSelfDirty)
			{
				using (BypassPropertyChecks)
				{
					//Stub: Write Data to the corresponding DB Object
					//dbObject.ArtMpardId = ArtMpardId;
					//dbObject.MparArtMparId = MparArtMparId;
					//dbObject.Lang = Lang;
					//dbObject.Descr = Descr;
					//dbObject.ShortDescr = ShortDescr;
					//dbObject.InsDat = InsDat;
					//dbObject.InsOper = InsOper;
					//dbObject.MutDat = MutDat;
					//dbObject.MutOper = MutOper;
					//dbObject.Save();
				}

			}

			FieldManager.UpdateChildren(this);
		}

		 [Transactional(TransactionalTypes.TransactionScope)]
		// ReSharper disable UnusedMember.Local
		private void Child_DeleteSelf(object parent)
		// ReSharper restore UnusedMember.Local
		{
			//Stub: Delete the corresponding DB Object
			ArtMpardId=0;
		}

		#endregion
	}

}

